package com.honry.identityaccess.domain.model;

import org.hibernate.SessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;

import com.honry.identityaccess.domain.model.identity.EncryptionService;
import com.honry.identityaccess.domain.model.identity.UserRepository;



public class DomainRegistry implements ApplicationContextAware {

	private static ApplicationContext applicationContext;
	
	/**
	 * 从Spring中获取加密服务。
	 * @return 加密服务实例
	 */
	public static EncryptionService encryptionService() {
        return (EncryptionService) applicationContext.getBean("encryptionService");
    }
	public static SessionFactory sessionFactory() {
        return  (SessionFactory)applicationContext.getBean("sessionFactory");
    }
	public static UserRepository userRepository() {
        return  (UserRepository)applicationContext.getBean("userRepository");
    }
	@Override
	public synchronized void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		System.out.print("a");
		if (DomainRegistry.applicationContext == null) {
            DomainRegistry.applicationContext = applicationContext;
        }
	}

}
